<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>短信发送</title>

    <!--引入本地 element-ui 的样式，-->
    <link rel="stylesheet" href="/admin/plugin/element-ui/index.css">
    <script type="text/javascript" src="/admin/js-css/js/vue.min.js"></script>
    <script type="text/javascript" src="/admin/plugin/element-ui/index.js"></script>

    <!--引入layui组件-->
    <link rel="stylesheet" href="/admin/plugin/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css"  media="all">
    <script src="/admin/plugin/layui/dist/layui.js" charset="utf-8"></script>

    <script type="text/javascript" src="/admin/js-css/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="/admin/js-css/js/mx1.0.js?v=1.1.1"></script>


</head>
<body>

    <div id="app">
        <div style="padding: 0px 20px;">
            <table border="0" >
                <tr>
                    <td width="70%">
                        <el-form  label-width="80px" size="small" >
                            <el-form-item label="一级：">
                                <el-checkbox-group v-model="keshi1">
                                    <el-checkbox :label="item.id" v-for="(item,index) in data1" @change="keshidata2" >{{item.ksmc}}</el-checkbox>

                                </el-checkbox-group>
                            </el-form-item>

                            <el-form-item label="二级：" v-if="data2.length > 0">
                                <el-checkbox-group v-model="keshi2">
                                    <el-checkbox :label="item.id" v-for="(item,index) in data2"  >{{item.ksmc}}</el-checkbox>
                                </el-checkbox-group>
                            </el-form-item>
                        </el-form>
                    </td>
                </tr>
            </table>
        </div>

        <div style="padding: 0px 20px;">
            <div style="margin-bottom: 10px;">
                <el-button type="primary" size="mini" @click="add_send">加入发送名单</el-button>
                <el-button type="primary" size="mini" @click="auto_dh">自动生成电话号码</el-button>
                <el-button type="primary" size="mini" @click="sendmsgconfrim">开始发送</el-button>
                <el-button type="primary" size="mini" @click="getlistdata">刷新</el-button>
                <el-button type="primary" size="mini" @click="deletedata">删除</el-button>
                <el-button type="text">{{addMsg}}</el-button>
            </div>

            <div>
                <el-table
                        ref="multipleTable"
                        tooltip-effect="dark"
                        :data="tableData"
                        :height="tableHeight"
                        @selection-change="handleSelectionChange"
                        border
                        style="width: 100%">
                    <el-table-column
                            type="selection"
                            width="55">
                    </el-table-column>

                    <el-table-column
                            prop="ssks"
                            label="所属科室"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="xm"
                            label="姓名"
                            width="180">
                    </el-table-column>
                    <el-table-column
                            prop="sjh"
                            label="手机号">
                    </el-table-column>

                    <el-table-column
                            prop="fssj"
                            label="发送时间">
                    </el-table-column>
                    <el-table-column
                            prop="fsbh"
                            label="发送编号">
                    </el-table-column>
                    <el-table-column
                            prop="fsjg"
                            label="发送结果">
                    </el-table-column>
                    <el-table-column
                            prop="fsr"
                            label="操作人">
                    </el-table-column>
                </el-table>
                <el-pagination
                        @current-change="handleCurrentChange"
                        @size-change="sizeChange"
                        background
                        layout="prev, pager, next,total,sizes"
                        :total="total"
                        :page-size="pageSize"
                        :page-sizes="pageSizes">
                </el-pagination>
            </div>

        </div>
    </div>

    <script>
        var vm = new Vue({
           el:"#app",
           data:{
               data1:[],
               keshi1:[],
               data2:[],
               keshi2:[],
               tableHeight:500,
               ddbh:"",
               addMsg:"",
               tableData: [],
               pageNumber:1,
               pageSize:20,
               total:0,
               pageSizes:[20,50,100,500],
               multipleSelection:[],
               setIntervalId : "",
           },
           created(){
               this.tableHeight = parseInt(document.documentElement.scrollHeight)-200;
               this.getdata();

           },
            methods:{
                auto_dh(){
                    let btn = {
                        btn: ['确定', '取消']
                        , yes: function (index, layero) {
                            //按钮【按钮一】的回调
                            var win = getTopIframe(layero);
                            let issubmit = win.verification();
                            if (!issubmit) {
                                return;
                            }
                            let data = win.getData();
                            let i = top.layer.load();
                            data["ddbh"] = vm.ddbh;
                            let psubmit = {
                                tableId: getTableId("3298"),
                                mapdata: data
                            }
                            postBody("/admin/api/DataManagementController/customPostData", psubmit, function (res) {
                                top.layer.close(i);
                                top.alert(res.msg);
                                vm.getListdata();
                            })
                        }
                        , btn2: function (index, layero) {
                            //按钮【按钮二】的回调
                            //return false 开启该代码可禁止点击该按钮关闭
                        }
                    };
                    top.f_layer_open_get("/admin/html/inputCustom/index.html?tableId="+getTableId("3298"), "50%", "50%", function () {

                    }, btn, "自动生成电话号码", {});
                },
               async deletedata(){
                   this.$confirm('确定要删除吗, 是否继续?', '提示', {
                       confirmButtonText: '确定',
                       cancelButtonText: '取消',
                       type: 'warning'
                   }).then(async () => {
                       let i = load();
                       const res = await postWebCustom(getTableId("3297"),{ids:""+this.multipleSelection});
                       layer.close(i);
                       top.alert(res.msg);
                       this.getlistdata();
                   }).catch(() => {
                       this.$message({
                           type: 'info',
                           message: '已取消发送'
                       });
                   });
               },

                handleSelectionChange(val) {
                    this.multipleSelection = [];
                    for(var a=0;a<val.length;a++){
                        this.multipleSelection[a] = val[a].id
                    }
                },
                //每页记录数改变
                sizeChange(val){
                    this.pageSize = val;
                    this.getListdata();
                },
                //开始翻页
                handleCurrentChange(val){
                    this.pageNumber = val;
                    this.getlistdata();
                },
               async getdata(){
                 const res = await postWebCustom(getTableId("3274"),{});
                 this.data1 = res.data;

                 //获取发送单编号
                   const res2 = await postWebCustom(getTableId("3278"),{});
                   this.ddbh = res2.data;

               },
                async keshidata2(){
                    const res = await postWebCustom(getTableId("3275"),{ids:""+this.keshi1});
                    this.data2 = res.data;
                },
                async getlistdata(){
                   let searchInputDtos = {"fsbh":{key:"fsbh",value:this.ddbh,type:"0"}};
                   let pagesimpli = {pageNumber:""+this.pageNumber,pageSize:""+this.pageSize,orderBy:"id desc",tableId:getTableId("3277"),searchInputDtos:searchInputDtos};
                   let pagedata = await pageAdmin(pagesimpli);
                   this.tableData = pagedata.data.rows;
                   this.total = parseInt(pagedata.data.total);
                },
                async sendmsgconfrim(){
                    this.$confirm('确定要发送短信码, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.sendMsg();
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消发送'
                        });
                    });
                },
                async sendMsg(){
                  const res = await postWebCustom(getTableId("3281"),{});
                  top.alert(res.msg);
                },
                async add_send(){
                    const res = await postWebCustom(getTableId("3276"),{keshi2:""+this.keshi2});
                    top.alert(res.msg);
                    this.getlistdata();
                    this.setIntervalId = setInterval(function (){
                        vm.getAddMsg();
                    },1000);
                },
                async getAddMsg(){
                  const res = await postWebCustom(getTableId("3279"),{});
                  if(res.code == 1 && res.data!="1"){
                      let mapod = res.data;
                      if(mapod.over == "1"){
                          window.clearInterval(this.setIntervalId);
                          this.getlistdata();
                      }
                      this.addMsg = res.data.msg;
                  }
                }
            }
        });
    </script>
</body>
</html>